﻿using System.Windows;
using System.Windows.Controls;

namespace NielsHebling.UnitTestResultViewerForSL.Controls
{
    public class ListViewItemStyleSelector : StyleSelector
    {
        private int i;
        public override Style SelectStyle(object item, DependencyObject container)
        {
            // makes sure the first item always gets the first style, even when restyling
            ItemsControl ic = ItemsControl.ItemsControlFromItemContainer(container);
            if (item == ic.Items[0])
            {
                i = 0;
            }
            string styleKey;
            if (i % 2 == 0)
            {
                styleKey = "ListViewItemStyle1";
            }
            else
            {
                styleKey = "ListViewItemStyle2";
            }
            i++;
            return (Style)(ic.FindResource(styleKey));
        }
    }
}
